#include "homepage.h"
#include "ui_homepage.h"

HomePage::HomePage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HomePage)
{
    ui->setupUi(this); 
    resize(800,600);
    initWindow();
}

HomePage::~HomePage()
{
    delete ui;
}

void HomePage::initWindow()
{
    //this->setWindowFlag(Qt::FramelessWindowHint);
    QDateTime curTime = QDateTime::currentDateTime();
    timer = new QTimer(this);
    connect(timer,&QTimer::timeout,[this]()
    {
        ui->TimeLabel->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"));
            });
    timer->start(1000);

    detectionPage = new DetectionWindow; //  DetectionWindow 是检测窗口页面的类
    setupwidget = new setupWidget;
    datawidget = new DataBaseWindow;
    mvdWidget = new MVDMainWindow;

//    stackedWidget = new QStackedWidget;

    ui->stackedWidget->addWidget(detectionPage); // 将检测页面添加到 stackedWidget
    ui->stackedWidget->addWidget(setupwidget); // 将设置页面添加到 stackedWidget
    ui->stackedWidget->addWidget(datawidget); // 将数据页面添加到 stackedWidget
    ui->stackedWidget->addWidget(mvdWidget); // 将设备页面添加到 stackedWidget

//    ui->verticalLayout->addWidget(stackedWidget); // 将 stackedWidget 添加到水平布局中
    connect(ui->DecButton,&QToolButton::clicked,this,&HomePage::on_DecButton_clicked);
    connect(ui->SetButton,&QToolButton::clicked,this,&HomePage::on_SetButton_clicked);
   //connect(ui->closeButton,&QPushButton::clicked,this,&HomePage::on_closeButton_clicked);

}

void HomePage::closeEvent(QCloseEvent *event)
{
    QMessageBox::StandardButton resButton = QMessageBox::question(this, "确认关闭", "是否确认关闭窗口？", QMessageBox::No | QMessageBox::Yes, QMessageBox::Yes);
    if (resButton == QMessageBox::Yes) {
        event->accept();
    }
    else
    {
        event->ignore();
    }

}

void HomePage::on_DecButton_clicked()
{
   ui->stackedWidget->setCurrentWidget(detectionPage);
}

void HomePage::on_closeButton_clicked()
{
    this->close();
}

void HomePage::on_SetButton_clicked()
{
    ui->stackedWidget->setCurrentWidget(setupwidget);
}

void HomePage::on_DataButton_clicked()
{
    ui->stackedWidget->setCurrentWidget(datawidget);
}

void HomePage::on_EquipmentButton_clicked()
{
    ui->stackedWidget->setCurrentWidget(mvdWidget);
}
